//
// Copyright (c) 2009-2011, chunquedong
//
// This file is part of ChunMap project
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
//
// History:
//   2011-09-04  Jed Young  Creation
//

using chunmapModel
using chunmapData
using chunmapRaster

@Js
class RasterLayer : Layer
{
  private RasterDataSource dataSource

  new makeUri(Type type, Uri uri, |->|? f)
  {
    dataSource = type.make([uri, f])
    renderer = Renderer.makeDef(Symbolizer[RasterSym{}])
    name = type.name
  }

  new make(|This| f) { f(this) }

  override Envelope envelope() { dataSource.envelope }

  override protected Void renderLayer(Int i, RenderEnv r)
  {
    cond := Condition
    {
      it.envelope = r.view.getBufferEnvelope
      scale = r.view.scale
      w = r.view.width
      h = r.view.height
    }
    dataSource.each(cond) |f|
    {
      r.data = f
      renderer.draw(r, i)
    }
  }
}